home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / littlest / littl-st.lha / manual.ms < prev    next >
Text File  |  1993-08-10  |  31KB  |  836 lines

  1. .TL
  2. Little Smalltalk Users Manual - Version Three
  3. .AU
  4. Tim Budd
  5. .AI
  6. Department of Computer Science
  7. Oregon State University
  8. Corvallis, Oregon
  9. 97331 USA
  10. .AB
  11. .PP
  12. Version three of Little Smalltalk was designed specifically to
  13. be easy to port
  14. to new machines and operating systems.  
  15. This document provides the basic information needed to use Version Three of
  16. Little Smalltalk, plus information needed by those wishing to undertake the
  17. job of porting the system to a new operating environment.
  18. .AE
  19. .PP
  20. The first version of Little Smalltalk, although simple, small and fast, was in 
  21. a number of very critical ways very Unix specific.  Soon after the
  22. publication of the book \fIA Little Smalltalk\fP, requests started flooding
  23. in asking if there existed a port to an amazingly large number of different
  24. machines, such as the IBM PC, the Macintosh, the Acorn, the Atari, and even
  25. such systems as DEC VMS.  Clearly it was beyond our capabilities to
  26. satisfy all these requests, however in an attempt to meet them partway in
  27. the summer of 1988 I designed a second version of Little Smalltalk, which
  28. was specifically designed to be less Unix specific and more amenable to
  29. implementation of different systems.
  30. .PP
  31. This document describes is divided into two parts.  In part one I describe
  32. the basic features of the user interface.  This is essential information
  33. for anybody wishing to use the system.  In part two we give the basic
  34. information needed by anybody wishing to undertake the task of porting
  35. version three Little Smalltalk to a new machine.
  36. .NH
  37. Getting Started
  38. .PP
  39. How you get started depends upon what kind of system you are working on.
  40. Currently there are two styles of interface supported.  A line-oriented,
  41. tty style stdin interface is available, which runs under Unix and other systems.
  42. There is also a window based system which runs under X-windows and on the
  43. Mac.
  44. .NH 2
  45. The stdin/stdout interface
  46. .PP
  47. Using the stdin/stdout interface, there is a prompt (the ``>'' caracter)
  48. typed to indicate the system is waiting for input.  
  49. Expressions are read at the keyboard and
  50. evaluated following each carrage return.  The result of the expression
  51. is then printed.
  52. .DS I
  53. >    5 + 7
  54. 12
  55. .DE
  56. Global variables can be created simply by assigning to a name.
  57. The value of an assignment statement is the value of the right hand side.
  58. .DS I
  59.     x <- 3
  60. 3
  61. .DE
  62. Multiple expressions can appear on the same line separated by periods.
  63. Only the last expression is printed.
  64. .DS I
  65.     y <- 17.  3 + 4
  66. 7
  67. .DE
  68. .NH 2
  69. The windowing interface
  70. .PP
  71. The windowing interface is built on top of guido van rossums standard
  72. window package, and runs on top of systems that support standard windows.
  73. These include X-11 and the Macintosh.
  74. .PP
  75. When you start up the system, there will be a single window titled
  76. ``workspace''.  You can enter expressions in the workspace, then select either
  77. the menu items ``do it'' or ``print it''.
  78. Both will evaluate the expression; the latter, in addition, will print the
  79. result.
  80. .PP
  81. A number of other memu commands are also available.  These permit you to
  82. save the current image, exit the system, or start the browser.
  83. .PP
  84. The browser is an interface permiting you to easily view system code.
  85. Selecting a class in the first pane of the browser brings up a second pane
  86. in which you can select methods, selecting a method brings up a third pane
  87. in which you can view and edit text.  Selecting ``compile'' following the
  88. editing of text will attempt to compile the method.  If no errors are
  89. reported, the method is then available for execution.
  90. .NH
  91. Exploring and Creating
  92. .PP
  93. This section describes how to discover information about existing objects 
  94. and create new objects using the Little Smalltalk
  95. system (version three).  
  96. In Smalltalk one communicates with objects by passing messages to them.
  97. Even the addition message + is treated as a message passed to the
  98. first object 5, with an argument represented by the second object.  
  99. Other messages can be used to discover
  100. information about various objects.
  101. The most basic fact you can discover about an object is its class.
  102. This is given by the message \fBclass\fP, as in the following examples:
  103. .DS I
  104. >    7 class 
  105. Integer
  106. >    nil class
  107. UndefinedObject
  108. .DE
  109. .PP
  110. Occasionally, especially when programming, one would like to ask whether
  111. the class of an object matches some known class.  One way to do this would
  112. be to use the message \fB= =\fP, which tells whether two expressions 
  113. represent the same object:
  114. .DS I
  115. >    ( 7 class = = Integer)
  116. True
  117. >    nil class = = Object
  118. False
  119. .DE
  120. .PP
  121. An easier way is to use the message \fBisMemberOf:\fP;
  122. .DS I
  123. >    7 isMemberOf: Integer
  124. True
  125. >    nil isMemberOf: Integer
  126. False
  127. .DE
  128. .PP
  129. Sometimes you want to know if an object is an instance of a particular
  130. class or one if its subclasses; in this case the appropriate message is
  131. \fBisKindOf:\fP.
  132. .DS I
  133. >    7 isMemberOf: Number
  134. False
  135. >    7 isKindOf: Number
  136. True
  137. .DE
  138. .PP
  139. All objects will respond to the message \fBdisplay\fP by telling a little
  140. about themselves.  Many just give their class and their printable
  141. representation:
  142. .DS I
  143. >    7 display
  144. (Class Integer) 7
  145. >    nil display
  146. (Class UndefinedObject) nil
  147. .DE
  148. .LP
  149. Others, such as classes, are a little more verbose:
  150. .DS I
  151. >    Integer display
  152. Class Name: Integer
  153. SuperClass: Number
  154. Instance Variables:
  155. no instance variables
  156. Subclasses:
  157. .DE
  158. .LP
  159. The display shows that the class \fBInteger\fP is a subclass of class
  160. \fBNumber\fP (that is, class \fBNumber\fP is the superclass of
  161. \fBInteger\fP).  There are no instance variables for this class, and it
  162. currently has no subclasses.  
  163. All of this information could be obtained by means of other messages,
  164. although the \fBdisplay\fP form is the easiest.
  165. [ Note: at the moment printing subclasses takes a second or two.  I'm not
  166. sure why.]
  167. .DS I
  168. >    List variables display
  169. links
  170. >    Integer superClass
  171. Number
  172. >    Collection subClasses display
  173. IndexedCollection
  174. Interval
  175. List
  176. .DE
  177. About the only bit of information that is not provided when one passes the
  178. message \fBdisplay\fP to a class
  179. is a list of methods the class responds to.  There are two
  180. reasons for this omission; the first is that this list can often be quite
  181. long, and we don't want to scroll the other information off the screen
  182. before the user has seen it.  The second reason is that there are really
  183. two different questions the user could be asking.  The first is what
  184. methods are actually implemented in a given class.  A list containing
  185. the set of methods implemented in a class can be found by passing the
  186. message \fBmethods\fP to a class.
  187. As we saw with the message
  188. \fBsubClasses\fP shown above, the command \fBdisplay\fP prints this
  189. information out one method to a line:
  190. .DS I
  191. >    True methods display
  192. #ifTrue:ifFalse:
  193. #not
  194. .DE
  195. .PP
  196. A second question that one could ask is what message selectors an instance of a
  197. given class will respond to, whether they are inherited from superclasses
  198. or are defined in the given class.  This set is given in response to the
  199. message \fBrespondsTo\fP. [ NOTE: again form some reason I'm not sure of
  200. this command seems to take a long time to execute ].
  201. .DS I
  202. >    True respondsTo display
  203. #class
  204. #==
  205. #hash
  206. #isNil
  207. #display
  208. #=
  209. #basicSize
  210. #isMemberOf:
  211. #notNil
  212. #print
  213. #basicAt:put:
  214. #isKindOf:
  215. #basicAt:
  216. #printString
  217. #or:
  218. #and:
  219. #ifFalse:ifTrue:
  220. #ifTrue:
  221. #ifFalse:
  222. #not
  223. #ifTrue:ifFalse:
  224. .DE
  225. .PP
  226. Alternatively, one can ask whether instances of a given class will respond
  227. to a specific message by writing the message selector as a symbol:
  228. .DS I
  229. >    String respondsTo: #print
  230. True
  231. >    String respondsTo: #+
  232. False
  233. .DE
  234. .PP
  235. The inverse of this would be to ask what classes contain methods for a
  236. given message selector.  Class \fBSymbol\fP defines a method to yield just
  237. this information:
  238. .DS I
  239. >    #+ respondsTo display
  240. Integer
  241. Number
  242. Float
  243. .DE
  244. .PP
  245. The method that will be executed in response to a given message selector
  246. can be displayed by means of the message \fBviewMethod:\fP
  247. .DS I
  248. >    Integer viewMethod: #gcd:
  249. gcd: value
  250.     (value = 0) ifTrue: [ \(ua self ].
  251.     (self negative) ifTrue: [ \(ua self negated gcd: value ].
  252.     (value negative) ifTrue: [ \(ua self gcd: value negated ].
  253.     (value > self) ifTrue: [ \(ua value gcd: self ].
  254.     \(ua value gcd: (self rem: value)
  255. .DE
  256. .PP
  257. Some Smalltalk systems make it very difficult for you to discover the
  258. bytecodes that a method gets translated into.  Since the primary goal of
  259. Little Smalltalk is to help the student to discover how a modern very high
  260. level language is implemented, it makes sense that the system should help
  261. you as much as possible discover everything about its internal structure.
  262. Thus a method, when presented with the message \fBdisplay\fP, will print
  263. out its bytecode representation.
  264. .DS I
  265. >    Char methodNamed: #isAlphabetic ; display
  266. Method #isAlphabetic
  267.     isAlphabetic
  268.         \(ua (self isLowercase) or: [ self isUppercase ]
  269.  
  270. literals
  271. Array ( #isLowercase #isUppercase )
  272. bytecodes
  273. 32 2 0
  274. 129 8 1
  275. 144 9 0
  276. 250 15 10
  277. 9 0 9
  278. 32 2 0
  279. 129 8 1
  280. 145 9 1
  281. 242 15 2
  282. 245 15 5
  283. 241 15 1
  284. .DE
  285. .PP
  286. Bytecodes are represented by four bit opcodes and four bit operands, with
  287. occasional bytes representing data (more detail can be found in the book).
  288. The three numbers written on each line for the bytecodes represent the 
  289. byte value followed by the upper four bits and the lower four bits.
  290. .PP
  291. .PP
  292. If you have written a new class and want to print the class methods on a
  293. file you can use the message \fBfileOut:\fP, after first creating a file to
  294. write to.  Both classes and individual methods can be filed out, and
  295. several classes and/or methods can be placed in one file.
  296. [ NOTE - file out doesn't work yet ].
  297. .DS I
  298. >    f \(<- File new
  299. >    f name: 'foo.st'
  300. >    f open: 'w'
  301. >    Foo fileOut: f
  302. >    Bar fileOut: f
  303. >    Object fileOutMethod: #isFoo to: f
  304. >    f close
  305. .DE
  306. .LP
  307. The file ``newfile'' will now have a printable representation of the
  308. methods for the class Foo.
  309. These can subsequently be filed back into a different smalltalk image.
  310. .DS I
  311. >    f \(<- File new
  312. >    f name: 'foo.st'
  313. >    f open: 'r'
  314. >    f fileIn
  315. >    2 isFoo
  316. False
  317. .DE
  318. .PP
  319. Finally, once the user has added classes and variables and made whatever other
  320. changes they want, the message \fBsaveImage\fP, passed to the pseudo
  321. variable \fBsmalltalk\fP, can be used to save an entire object image on a file.
  322. If the writing of the image is successful, a message will be displayed.
  323. .DS I
  324. >    smalltalk saveImage
  325. Image name? newimage
  326. image newimage created
  327. >    
  328. .DE
  329. .PP
  330. Typing control-D causes the interpreter to exit.
  331. .PP
  332. When the smalltalk system is restarted, an alternative image, such as the
  333. image just created, can be specified by giving its name on the argument
  334. line:
  335. .DS I
  336. st newimage
  337. .DE
  338. .PP
  339. Further information on Little Smalltalk can be found in the book.
  340. .NH 
  341. New Methods, New Classes
  342. .NH 2
  343. Stdin/Stdout Interface
  344. .PP
  345. New functionality can be added using the message \fBaddMethod\fP.
  346. When passed to an instance of \fBClass\fP, this message drops the user into
  347. a standard Unix Editor.  A body for a new method can then be entered.
  348. When the user exits the editor, the method body is compiled.  If it is
  349. syntactically correct, it is added to the methods for the class.  If it is
  350. incorrect, the user is given the option of re-editing the 
  351. method.  The user is first prompted for the name of the group to which the
  352. method belongs.
  353. .DS I
  354. >    Integer addMethod
  355. \& ... drop into editor and enter the following text
  356. % x
  357.     \(ua ( x + )
  358. \& ... exit editor
  359. compiler error: invalid expression start )
  360. edit again (yn) ?
  361. \& ...
  362. .DE
  363. .PP
  364. In a similar manner, existing methods can be editing by passing their
  365. selectors, as symbols to the message \fBeditMethod:\fP.
  366. .DS I
  367. >    Integer editMethod: #gcd:
  368. \& ... drop into editor working on the body of gcd:
  369. .DE
  370. .PP
  371. The name of the editor used by these methods is taken from a string
  372. pointed to by the global variable \fIeditor\fP.  Different editors can be
  373. selected merely by redefining this value:
  374. .DS I
  375. editor \(<- 'emacs'
  376. .DE
  377. .PP
  378. Adding a new subclass is accomplished by sending the message
  379. \fBaddSubClass:instanceVariableNames:\fP to the superclass object.
  380. The the first argument is a symbol representing the name, the second is a
  381. string containing the names of any instance variables.
  382. .DS I
  383. >    Object addSubClass: #Foo instanceVariableNames: 'x y'
  384. Object
  385.     Foo display
  386. Class Name: Foo
  387. SuperClass: Object
  388. Instance Variables:
  389. y
  390. .DE
  391. Once defined, \fBaddMethod\fP and \fBeditMethod:\fP can be used to provide
  392. functionality for the new class.
  393. .PP
  394. New classes can also be added using the fileIn mechanism.
  395. .NH 2
  396. The Windowing Interface
  397. .PP
  398. Using the windowing interface, new classes are created by selecting the
  399. menu item \fIadd class\fP in the first browser window.  New Methods are
  400. selected by choosing \fInew method\fP in a subsequent window.
  401. .NH
  402. Incompatibilities with the Book
  403. .PP
  404. It is unfortunately the case that during the transition from version 1 (the
  405. version described in the book) and version 3, certain changes to the user
  406. interface were required.  I will describe these here.
  407. .PP
  408. The first incompatibility comes at the very beginning.  In version 1 there
  409. were a great number of command line options.  These have all been
  410. eliminated in version three.  In version three the only command line option is
  411. the file name of an image file.
  412. .PP
  413. The interface to the editor has been changed.  In version one this was
  414. handled by the system, and not by Smalltalk code.  This required a command
  415. format that was clearly not a Smalltalk command, so that they could be
  416. distinguished.  The convention adopted was to use an APL style system
  417. command:
  418. .DS I
  419. )e filename
  420. .DE
  421. In version three we have moved these functions into Smalltalk code.  Now
  422. the problem is just the reverse, we need a command that is a Smalltalk
  423. command.  In addition, in version one entire classes were edited at once,
  424. whereas in version three only individual methods are edited.  As we have
  425. already noted, the new commands to add or edit methods are as follows:
  426. .DS I
  427. \fIclassname\fP addMethod
  428. \fIclassname\fP editMethod: \fImethodname\fP
  429. .DE
  430. .PP
  431. The only other significant syntactic change is the way primitive methods
  432. are invoked.  In version one these were either named or numbered, 
  433. something like the following:
  434. .DS I
  435. <primitive 37 a b>
  436. <IntegerAdd a b>
  437. .DE
  438. In version three we have simply eliminated the keyword \fBprimitive\fP, so
  439. primitives now look like:
  440. .DS I
  441. <37 a b>
  442. .DE
  443. .PP
  444. There are far fewer primitives in version three, and much more of the system
  445. is now performed using Smalltalk code.
  446. .PP
  447. In addition to these syntactic changes, there are various small changes in
  448. the class structure.  I hope to have a document describing these changes at
  449. some point, but as of right now the code itself is the best description.
  450. .NH
  451. Implementors Information
  452. .PP
  453. The remainder of this document contains information necessary for those
  454. wishing to examine or change the source code for the Little Smalltalk
  455. system.
  456. .NH 2
  457. Finding Your Way Around
  458. .de Mc
  459. .IP \\\\fB\\$1\\\\fP
  460. .br
  461. ..
  462. .PP
  463. In this section we describe the files that constitute version three of
  464. the Little Smalltalk system.
  465. .Mc memory.c
  466. This is the memory manager, the heart of the Little Smalltalk system.
  467. Although it uses a straightforward reference counting scheme, a fair amount
  468. of design effort has gone into making it as fast as possible.  By modifying
  469. it's associated description file (memory.h) a number of operations can be
  470. specified either as macros or as function calls.  The function calls
  471. generally perform more error checking, and should be used during initial
  472. development.  Using macros, on the other hand, can improve performance
  473. dramatically.  At some future date we hope to make available both reference
  474. counting and garbage collection versions of the memory manager.
  475. .Mc names.c
  476. The only data structures used internally in the Little Smalltalk system are
  477. arrays and name tables.  A name table is simply an instance of class
  478. \fBDictionary\fP in which keys are symbols.  Name tables are used to
  479. implement the dictionary of globally accessible values, \fBsymbols\fP,
  480. and to implement method tables.  This module provides support for reading
  481. from name tables.
  482. .Mc news.c
  483. This module contains several small utility routines which create new
  484. instances of various standard classes.
  485. .Mc interp.c
  486. This module implements the actual bytecode interpreter.
  487. It is the heart of the system, where most execution time is spent.
  488. .Mc primitive.c
  489. This module contains the code that is executed to perform primitive
  490. operations.  Only the standard primitives (see the section on primitives)
  491. are implemented in this module.  File primitives and system specific
  492. primitives are implemented in another module, such as unixio.c for the Unix
  493. system and macio.c for the Macintosh version.
  494. .Mc unixio.c,filein.c
  495. These two modules contains I/O routines.
  496. .Mc lex.c,parser.c
  497. The files lex.c and parser.c are the lexical analyzer and parser,
  498. respectively, for compiling the textual representation of methods into
  499. bytecodes.  In the current version parsing is done using a simple (although
  500. large) recursive descent parser.
  501. .Mc st.c
  502. The file st.c is the front end for the Unix version of Little Smalltalk.
  503. On the Macintosh version it is replaced by the pair of files macmain.c and
  504. macevent.c.
  505. .Mc initial.c
  506. This module contains code that reads the module form of Smalltalk code,
  507. creating an object image.
  508. This is not part of the Smalltalk bytecode interpreter, but is used in
  509. building the initial object image (see next section).
  510. .PP
  511. There are description files ( .h files, in standard C convention) which
  512. describe many of the modules described above.  In addition, there is a very
  513. important file called env.h (for ``environment'').  This file describes the
  514. characteristics of the operating system/machine you are running on.
  515. The general structure of this file is that the user provides one definition
  516. for their system, for example
  517. .DS I
  518. \&# define LIGHTC
  519. .DE
  520. to indicate using the Lightspeed C compiler on the macintosh, for example.
  521. Following this are block of code which, based on this one definition,
  522. define other terms representing the specific attributes of this system.
  523. Where ever possible new code should be surrounded by \fIifdef\fP directives
  524. based on words defined in this manner.
  525. The next section describes this in more detail.
  526. .NH 2
  527. Defining System Characteristics
  528. .PP
  529. There are many ways in which compilers and operating systems differ 
  530. from each other.
  531. A fair amount of work has been expanded in making sure the software will
  532. operate on most machines, which requires that different code fragments be
  533. used on different systems.  In large part these are controlled by a single
  534. ``meta-define'' in the file env.h.  Setting this one value then causes the
  535. expansion of another code segment, which then defines many more options.
  536. .PP
  537. In the event that you are attempting to port the software to a system that
  538. has not previously been defined, you will need to decide which set of
  539. options to enable.  The next two sections contain information you may need
  540. in making this determination.
  541. .SH
  542. Define Options
  543. .PP
  544. Many options are specified merely by giving or not giving a DEFINE
  545. statement in the file env.h.  The following table presents the meaning for
  546. each of these values:
  547. .Mc ALLOC
  548. Defined If there is an include file called alloc.h which defines calloc, 
  549. malloc, and the like.
  550. .Mc BINREADWRITE
  551. Defined if the fopen specification for binary files must include the "b"
  552. modifier.  This is true on many MS-DOS inspired systems.
  553. .Mc NOENUMS
  554. Defined if enumerated datatypes are not supported.  If defined, these will
  555. be replaced by #define constants.
  556. .Mc NOTYPEDEF
  557. Defined if the typedef construct is not supported.  If defined, these will
  558. be replaced by #define constructs.
  559. .Mc NOVOID
  560. Defined if the void keyword is not recognized.
  561. If defined, expect \fIlint\fP to complain a lot about functions returning
  562. values which are sometimes (or always) ignored.
  563. .Mc SIGNALS
  564. Used if \fIboth\fP the <signals.h> package and the <longjmp.h> package are
  565. available, and if the routine used to set signals is signal.
  566. Incompatible with \fBSSIGNALS\fP.
  567. .Mc SSIGNALS
  568. Used if \fIboth\fP the <signals.h> package and the <longjmp.h> package are
  569. available, and if the routine used to set signals is ssignal.
  570. Incompatible with \fBSIGNALS\fP.
  571. .Mc STRING
  572. Used if the string functions (strcpy, strcat and the like) are found in
  573. <string.h>.  This switch is incompatible with \fBSTRINGS\fP.
  574. .Mc STRINGS
  575. Used if the string functions (strcpy, strcat and the like) are found in
  576. <strings.h>.  This switch is incompatible with \fBSTRING\fP.
  577. .LP
  578. In addition, several routines can optionally be replaced by macros for
  579. greater efficiency.  See the file memory.h for more information.
  580. .NH 2
  581. Building an Initial Object Image
  582. .PP
  583. There are two programs used in the Little Smalltalk system.  The first is
  584. the actual bytecode interpreter.  The use of this program is described in
  585. detail in other documents (see ``Exploring and Creating'').
  586. The Little Smalltalk system requires, to start, a snapshot representation of
  587. memory.  This snapshot is called an object image, and the purpose of the
  588. second program, the initial object image maker, is to construct an 
  589. initial object image.
  590. In theory, the this program need only be run once, by the system administrator,
  591. and thereafter all users can access the same standard object image.
  592. .PP
  593. The object image format is binary.  However, since the format for binary
  594. files will undoubtedly differ from system to system, the methods which
  595. will go into the initial image are distributed in textual form, called
  596. module form.  Several modules are combined to create an object image.
  597. The following describes the modules distributed on the standard tape, 
  598. in the order they should be processed, and their purposes.
  599. .Mc basic.st
  600. This module contains the basic classes and methods which should be common
  601. to all implementations of Little Smalltalk.
  602. .Mc mag.st
  603. This module contains methods for those objects having magnitude, which are
  604. the basic subclasses of Magnitude.
  605. .Mc collect.st
  606. This module contains methods for the collection subclasses.
  607. .Mc file.st
  608. This module contains the classes and methods used for file operations.
  609. Although all implementations should try to support these operations, it may
  610. not always be possible on all systems.
  611. .Mc unix.st
  612. This module contains unix - specific commands, which may differ from those
  613. used under other operating systems.
  614. .Mc mult.st
  615. This module contains code for the multiprocessing scheduler.
  616. .Mc init.st
  617. This module contains code which is run to initialize the initial object
  618. image.  These methods disappear after they have been executed.
  619. (or should; they don't really yet).
  620. .Mc test.st
  621. This file contains various test cases.
  622. .NH 2
  623. Object Memory
  624. .PP
  625. There are several datatypes, not directly supported by C, that are used in
  626. the Little Smalltalk system.  The first of these is the datatype byte.
  627. A byte is an eight bit unsigned (hence positive) quantity.
  628. On many systems the appropriate datatype is unsigned char, however on other
  629. systems this declaration is not recognized and other forms may be required.
  630. To aid in coverting to and from bytes the macro byteToInt() is used, which
  631. converts a byte value into an integer.  In addition, the routines byteAt
  632. and byteAtPut are used to get and put bytes from byte strings.
  633. .PP
  634. The other datatype is that used to represent object points.  On most
  635. machines in which a short is 16 bits, the datatype short should suffice.
  636. Much more information on the memory module can be found in the file
  637. memory.h.
  638. .NH 2
  639. The Bottom End
  640. .PP
  641. The opposite extreme from the front end are those messages that originate
  642. within the Smalltalk bytecode interpreter and must be communicated to the user.
  643. We can divide these into two different classes of communications, editing
  644. operations and input/output operations.  The following sections will treat
  645. each of these individually.
  646. .NH 3
  647. Editing
  648. .PP
  649. We have already mentioned that commands entered by the user are converted
  650. into methods, and passed to the same method compiler as all other methods.
  651. Before the user can create a new method, however, there must be some 
  652. mechanism for allowing the user to enter the method.
  653. .PP
  654. One approach would be to read the method from the standard input, just 
  655. as commands are read.  While easy to implement, this approach would soon
  656. prove unsatisfactory, since for every error the user would need to reenter
  657. the entire method.  So some form of update, or editing, must be
  658. provided.  Again, the Unix interface and the Macintosh interface solve
  659. this problem in radically different ways.
  660. .NH 4
  661. Editing Under Unix
  662. .PP
  663. A request to edit or add a method is given by sending either the message
  664. \fBaddMethod\fP or \fBeditMethod:\fP to a class.  The methods for these
  665. messages in turn call upon a common routine to perform the actual editing
  666. work.
  667. .DS I
  668. \fBaddMethod\fP
  669.     self doEdit: ''
  670.  
  671. \fBeditMethod:\fP name
  672.     self doEdit: ( methods at: name
  673.         ifAbsent: [ 'no such method ' print. \(ua nil ] ) text
  674.  
  675. \fBdoEdit:\fP startingText        | text |
  676.     text \(<- startingText.
  677.     [ text \(<- text edit.
  678.       (self addMethodText: text)
  679.         ifTrue: [ false ]
  680.         ifFalse: [ smalltalk inquire: 'edit again (yn) ? ' ]
  681.             ] whileTrue
  682. .DE
  683. .PP
  684. The Unix and MS-DOS versions of the system provide a method \fBedit\fP as
  685. part of the functionality of class \fBString\fP.  When \fBedit\fP is passed
  686. to a string, an editing environment is established.  The user performs
  687. editing tasks in that environment, and then exits the editing environment.
  688. Under Unix, this functionality is implemented using the file system.
  689. .DS I
  690. \fBedit\fP    | file text |
  691.     file \(<- File new; 
  692.         scratchFile;
  693.         open: 'w';
  694.         print: self;
  695.         close.
  696.     (editor, ' ', file name) unixCommand.
  697.     file open: 'r'.
  698.     text \(<- file asString.
  699.     file close; delete.
  700.     \(ua text
  701. .DE
  702. .PP
  703. A file is created, and the contents of the string written to it.
  704. Then a standard Unix editor (given by the global variabled \fBeditor\fP)
  705. is invoked to process the file.  After the user exits the editor, the
  706. contents of the file are read back as a string, the file is closed and
  707. deleted, and the string returned.  The command \fBunixCommand\fP is
  708. implemented as a primitive, which invokes the system() system call:
  709. .DS I
  710. \fBunixCommand\fP
  711.     \(ua <150 self>
  712. .DE
  713. .PP
  714. Although the \fBedit\fP message is used by the system only for editing
  715. methods, it is general enough for any editing application and there is no
  716. reason why the user cannot use it for other purposes.
  717. By the way, the \fBunixCommand\fP message is also used to implement file
  718. deletes.
  719. .DS I
  720. \fBdelete\fP
  721.     ('rm ', name) unixCommand
  722. .DE
  723. .PP
  724. On MS-Dos systems this command should be changed to \fBDEL\fP.
  725. .PP
  726. .NH 4
  727. Editing on the Macintosh
  728. .PP
  729. The Macintosh version takes an entirely different approach to the editing
  730. of methods.  
  731. As in the Unix version, the user requests editing using the commands
  732. \fBeditMethod:\fP and \fBaddNewMethod\fP.  And, as in the Unix version,
  733. these in turn invoke a common method.
  734. .DS I
  735. \fBaddMethod\fP
  736.     self doEdit: ( self printString, ': new method') text: ''
  737.  
  738.  
  739. \fBeditMethod:\fP name
  740.     self doEdit: (self printString, ': ', name)
  741.         text: (methods at: name
  742.                 ifAbsent: ['no such method' print. \(ua nil ]) text
  743. .DE
  744. .PP
  745. Here, however, when the user asks to edit a method, a new \fIediting
  746. window\fP is created.
  747. .DS I
  748. \fBdoEdit\fP: title \fBtext\fP: text    | w |
  749.     w \(<- EditWindow new; 
  750.         acceptTask: [ self addMethodText: w getString ] ;
  751.         title: title; create; print: text; showWindow
  752. .DE
  753. .PP
  754. The edit window is initialized with the current text of the method.
  755. Thereafter, the user can edit this using the standard Macintosh cut and
  756. paste conventions.  The user signifies they are satisfied with the result
  757. by entering the command \fBaccept\fP, which causes the \fIacceptTask:\fP
  758. block to be executed.  This block gets the text of the window (given by the
  759. message \fBgetString\fP) and passes it to \fBaddMethodText:\fP, which
  760. compiles the method, entering it in the method table if there are no
  761. errors.
  762. .NH 3
  763. Input/Output commands
  764. .PP
  765. Under the Unix system all input/output operations are performed using the
  766. file system and the global variables stdin, stdout and stderr.
  767. Thus the message \fBerror:\fP, in class \fBSmalltalk\fP, merely prints a
  768. message to the standard error output and exits.
  769. .PP
  770. The macintosh version, although using the same file routines, does not have
  771. any notion of standard input or standard output.  Thus error messages
  772. (such as from \fBerror:\fP) result in alert boxes being displayed.
  773. .PP
  774. There are also error messages that come from inside the Smalltalk
  775. interpreter itself.  These are of two types, as follows:
  776. .IP 1.
  777. System errors.  These are all funnelled through the routine sysError().
  778. System errors are caused by dramatically wrong conditions,
  779. and should generally cause the system to abort after printing the message
  780. passed as argument to sysError().
  781. .IP 2.
  782. Compiler errors.  As we noted earlier, the method compiler is used to
  783. parse expressions typed directly at the keyboard, so these message can
  784. also arise in that manner.  These are all funnelled through the routines
  785. compilError() and compilWarn(). These should print their arguments 
  786. (two strings), in an appropriate location on the users screen.
  787. Execution continues normally after call.
  788. .NH  2
  789. Primitives
  790. .PP
  791. Primitives are the means whereby actions that cannot be described directed
  792. in Smalltalk are performed.  In version three of the Little Smalltalk system,
  793. primitives are divided into three broad categories.
  794. .IP 1.
  795. Primitives numbered less than 119 are all standard, and both the meaning
  796. and the implementation of these should be the same
  797. in all implementations of Little Smalltalk.  These are largely just simple
  798. actions, such as mathematical operations.
  799. .IP 2.
  800. Primitives numbered 120-139 are reserved for file operations.  Although the
  801. meaning of these primitives should remain constant across all
  802. implementations, their implementation may differ.
  803. .IP 3.
  804. Primitives number 150-255 are entirely implementation specific, and thus in
  805. porting to a new system the implementor is free to give these any meaning
  806. desired.  For example under the Unix version there is, at present, only one 
  807. such primitive, used to perform the system() call.  On the other hand,
  808. the Macintosh version has dozens of primitives used to implement graphics
  809. functions, windowing function, editing and the like.
  810. .NH
  811. Distribution of New Implementations
  812. .PP
  813. The Little Smalltalk system is entirely public domain, and any user is free
  814. to redistribute it in any fashion they wish.  As a service to the Smalltalk
  815. community, I would appreciate it if new implementors could send me a
  816. listing of changes they make, so that they can be incorporated into one
  817. standard distribution.  Correspondence should be addressed to:
  818. .DS I
  819. Tim Budd
  820. Department of Computer Science
  821. Oregon State University
  822. Corvallis, Oregon
  823. 97331 USA
  824. .DE
  825. .PP
  826. Copies of the most recent distribution can also be obtained by writing to
  827. this address.  In mailing out distributions, there is a small charge for
  828. media and mailing costs.
  829. .NH
  830. New Features
  831. .PP
  832. If you type ``smalltalk echo'' all input will be echoed (tty interface
  833. only).  Typing smalltalk echo again undoes this.  This is useful for
  834. reading from scripts.
  835.